<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript">

	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
						    url:"<c:url value="/supplier/findsupplier.do"/>"+"?companyId=${companyId }",
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '新增',
										iconCls : 'icon-add',
										handler : function() {

											window
													.open(
															"<c:url value='/jsp/openIndexSun.jsp?url=/supplier/preSaveSupper.do'/>"+"?companyId=${companyId }",
															"sun",
															"width=1200px,height=600px,status=no,scrollbars=yes");

											$('#' + listDisplayEId).datagrid(
													'reload');
										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改',
										iconCls : 'icon-edit',
										handler : function() {

											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											//alert(row[0]['describ']+row[0]['codeTypeName']);
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												window
														.open(
																"<c:url value='/jsp/openIndexSun.jsp?url=/supplier/preUpdateSupplier.do'/>"
																		+ "?supplierId="
																		+ row[0]["supplierId"]
																		+ "&userId="
																		+ row[0]["userId"],
																"sun",
																"width=1200px,height=600px,status=no,scrollbars=yes");

												$('#' + listDisplayEId)
														.datagrid('reload');
											}
											$('#' + listDisplayEId).datagrid(
													'clearSelections');
										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_del',
										text : '删除',
										iconCls : 'icon-cancel',
										handler : function() {

											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var str = "supplierId="
														+ row[0]['supplierId'];
												$.messager
														.confirm(
																'提示',
																'是否删除该条记录？',
																function(r) {
																	if (r) {
																		$
																				.ajax({
																					type : 'post',
																					url : "<c:url value='/supplier/deleteSupplier.do'/>",
																					data : str,
																					dataType : "json",//设置查询参数及提交路径
																					success : function(
																							data) {
																						if (data.success) {
																							$.messager
																									.alert(
																											"提示",
																											"删除成功！",
																											'info');
																							$(
																									'#'
																											+ listDisplayEId)
																									.datagrid(
																											'reload');
																						} else {
																							$.messager
																									.alert(
																											"提示",
																											data.msg,
																											'warning');
																						}
																					},
																					error : function() {
																						$.messager
																								.alert(
																										"错误",
																										"系统错误，请联系管理员！",
																										'error');
																					}
																				});
																	}
																	$(
																			'#'
																					+ listDisplayEId)
																			.datagrid(
																					'reload');
																});
											}

										}

									},
									'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '查看资质',
										iconCls : 'icon-search',
										handler : function() {
											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											//alert(row[0]['describ']+row[0]['codeTypeName']);
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var new_win = window
														.open(
																"<c:url value='/jsp/openIndexSun.jsp?url=/supplier/preSupplierQualification.do'/>"
																		+ "?supplierId="
																		+ row[0]["supplierId"],
																"mainDiv",
																"width=1200px,height=600px,status=no,scrollbars=yes");
												new_win.focus();
												document.location = "<c:url value='/jsp/openIndexSun.jsp?url=/supplier/preSupplierQualification.do'/>"
														+ "?supplierId="
														+ row[0]["supplierId"];
											}
											$('#' + listDisplayEId).datagrid(
													'clearSelections');
										}
									} ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
							}
						});

	};
	$(document).ready(function() {
		initList('listDisplay');
	});
	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioRole' />";
	}
	//角色状态展示0：有效；1为失效
	function formatDGStateField(value, row, index, field) {
		if (!field) {
			field = this.field;
		}
		var fields = field.split('.');
		var fieldValue = row;
		for (var i = 0; i < fields.length; i++) {
			if (fieldValue[fields[i]] == 0) {
				fieldValue = "有效";
			} else if (fieldValue[fields[i]] == 1) {
				fieldValue = "失效";
			}
		}
		return fieldValue;
	}

	function formatSupType(value, row, index, field) {
		return findSupType(row['supplierId']);
	}

	function findSupType(supId) {
		var returnString;
		$.ajax({
			async : false,
			url : "<c:url value='/supplier/findSupType.do'/>" + "?supId="
					+ supId,
			type : "post",
			success : function(data) {
				if (typeof (data) == 'string') {
					data = JSON.parse(data);
				}
				returnString = data.materType;
			}
		});
		return returnString;
	}
</script>
</head>

<body>
	<table id="listDisplay" title="供应商列表" singleSelect=true
		iconCls="icon-list" idField="id"
		style="width: 800px; width: 1180px;" loadMsg="请稍候......"
		pagination="true" pageSize="10"
		pageList="[10,20,30,40,50,100,150,200]" sortName="roleId"
		rownumbers="true" sortOrder="asc">
		<thead>
			<tr>
				<th field="radioRole" width="25" align="center"
					formatter="formatRadio"></th>
				<th field="supplierId" width="80" sortable="true">ID</th>
				<th field="companyName" width="120" sortable="true" editor="text">
					供应商公司名</th>
				<th field="province" width="40" sortable="true" editor="text">
					省份</th>
				<th field="city" width="40" sortable="true" editor="text">市</th>
				<th field="street" width="140" sortable="true" editor="text">街</th>
				<th field="phone" width="120" sortable="true" editor="text">
					联系电话</th>
				<th field="mobile" width="120" sortable="true" editor="text">
					手机</th>
				<th field="isActive" width="60" formatter="formatDGStateField"
					sortable="true" editor="text">是否有效</th>
				<th field="insertTime" width="80" sortable="true" editor="datebox">
					注册时间</th>
				<th field="userId" width="100" sortable="true" editor="datebox" hidden='true'>
					登陆用户id</th>
				<th field="userName" width="200" sortable="true" editor="datebox">
					员工</th>
				<th field="content" width="100" sortable="true" editor="datebox"
					formatter="formatSupType">供货种类</th>


			</tr>
		</thead>
	</table>
</body>
</html>